<style>
a {
	color:#000000;
    font-size:12px;
	text-decoration: none;
}
</style>
<script type="text/javascript">
var auth_func_current_model_${action_id} = '${id?default('')}';
	$(function() {
		$('#func_treegrid_${action_id}').treegrid({
			url : '${request.contextPath}${namespace?default('')}/mp/auth/func-datagrid.json',
			queryParams:{'model.id':'${id?default('')}'},
			idField : 'id',
			treeField : 'text',
			parentField : 'pId',
			fit : true,
			nowrap:false,
			fitColumns : true,
			border : false,
			frozenColumns : [ [{
				title : 'bianhao',
				field : 'id',
				width : 150,
				hidden : true
			},{
				field : 'text',
				title : '${action.getDatagridTitle('name')}',
				width : 200
			} ] ],
			columns : [ [ {
				field : 'iconCls',
				title : '${action.getDatagridTitle('icon')}',
				width : 25,
				formatter : function(value) {
					if (!value) {
						return '';
					} else {
						return '<span class="'+value+'" style="display:inline-block;vertical-align:middle;width:16px;height:16px;"></span>';
					}
				}
			}, {
				field : 'attributes.url',
				title : '${action.getDatagridTitle('url')}',
				width : 150,
				formatter : function(value, row, index) {
					return row.attributes.url;
				}
			},  {
				field : 'attributes.operations',
				title : '${action.getDatagridTitle('operations')}',
				width : 250,
				formatter : function(value, row, index) {
					return row.attributes.operations;
				}
			},{
				field : 'attributes.sort',
				title : '${action.getDatagridTitle('sort')}',
				width : 30,
				formatter : function(value, row, index) {
					return row.attributes.sort;
				}
			},{
				field : 'attributes.disabled',
				title : '${action.getDatagridTitle('disabled')}',
				width : 30,
				formatter : function(value, row, index) {
					return row.attributes.disabled;
				}
			},{
				field : 'attributes.priority',
				title : '${action.getDatagridTitle('priority')}',
				width : 30,
				formatter : function(value, row, index) {
					return row.attributes.priority;
				}
			},{
				field : 'attributes.isOper',
				title : '${action.getDatagridTitle('isOper')}',
				width : 30,
				formatter : function(value, row, index) {
					return row.attributes.isOper;
				}
			}, {
				field : 'pId',
				title : '上级菜单ID',
				width : 150,
				hidden : true
			},{
				field : 'action',
				title : '${action.getProperty('net.esj.background.message','bg.datagrid.action')}',
				width : 50,
				formatter : function(value, row, index) {
					var reval = '';
					var dur = parseInt(row.attributes.durable);
					if( (dur&2) == 0){
						reval +='<a onclick="auth_func_edit_${action_id}(\''+row.id+'\');" href="javascript:;; ">${action.getProperty('net.esj.background.message','bg.datagrid.edit')}</a>&nbsp;';
					}
					if( (dur&1)  == 0){
						reval +='<a onclick="auth_func_delete_${action_id}(\''+row.id+'\');" href="javascript:;;" >${action.getProperty('net.esj.background.message','bg.datagrid.delete')}</a>';
					}
					return reval;
				}
			} ] ],
			toolbar : '#auth_func_datagrid_tb_${action_id}'
		});
	});

	function auth_func_add_${action_id}() {
		$('<div/>').dialog({
			href : '${request.contextPath}${namespace?default('')}/mp/auth/func-form.htm?action_id=${action_id}&key=${key?default('')}&model.id='+auth_func_current_model_${action_id},
			width : 600,
			height : 500,
			modal : true,
			maximizable:true,
			collapsible:false,
			minimizable:false,
			resizable:true,
			title : '${action.getText('form.add.title')}',
			buttons : [ {
				text : '${action.getProperty('net.esj.background.message','bg.datagrid.add')}',
				iconCls : 'icon-add',
				handler : function() {
					var d = $(this).closest('.window-body');
					$(d).find('#form_${action_id}').form('submit', {
						url : '${request.contextPath}${namespace?default('')}/mp/auth/func-add.json?key=${key?default('')}',
						onSubmit: function(){
							return $(this).form('validate');
        				},
						success : function(json) {
							eval("json="+json);
							$.messager.alert(json.title,json.msg,json.level);
							d.dialog('destroy');
							auth_func_reload_${action_id}();
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
	}
	function auth_func_edit_${action_id}(id) {
		$('<div>').dialog({
			href : '${request.contextPath}${namespace?default('')}/mp/auth/func-edit.htm?action_id=${action_id}&key=${key?default('')}&model.id='+auth_func_current_model_${action_id},
			width : 600,
			height : 500,
			modal : true,
			maximizable:true,
			collapsible:false,
			minimizable:false,
			resizable:true,
			title : '${action.getText('form.edit.title')}',
			buttons : [ {
				text : '${action.getProperty('net.esj.background.message','bg.datagrid.edit')}',
				iconCls : 'icon-edit',
				handler : function() {
					var d = $(this).closest('.window-body');
					$(d).find('#form_${action_id}').form('submit', {
						url : '${request.contextPath}${namespace?default('')}/mp/auth/func-update.json?key=${key?default('')}',
						onSubmit: function(){
							return $(this).form('validate');
        				},
						success : function(json) {
							eval("json="+json);
							$.messager.alert(json.title,json.msg,json.level);
							d.dialog('destroy');
							auth_func_reload_${action_id}();
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			},
			onLoad : function() {
				var d = $(this).closest('.window-body');
				$(d).find('#form_${action_id}').form('load', '${request.contextPath}${namespace?default('')}/mp/auth/func-load.json?key=${key?default('')}&id='+id+'&model.id='+auth_func_current_model_${action_id}+'&n='+Math.random());
			}
		});
	}
	
	function auth_func_delete_${action_id}(id) {
		if (id != undefined) {
			$('#func_treegrid_${action_id}').treegrid('select', id);
		}
		var node = $('#func_treegrid_${action_id}').treegrid('getSelected');
		if (node) {
			$.messager.confirm('${action.getProperty('net.esj.background.message','bg.message.info')}', '${action.getText('list.grid.delete.ask')}', function(b) {
				if (b) {
					$.ajax({
						url : '${request.contextPath}${namespace?default('')}/mp/auth/func-delete.json?key=${key?default('')}',
						data : {
							deletes : node.id
						},
						dataType : 'JSON',
						success : function(json) {
							$.messager.alert(json.title,json.msg,json.level);
							auth_func_reload_${action_id}();
						}
					});
				}
			});
		}
	}

	function auth_func_reload_${action_id}(){
		$.post('${request.contextPath}${namespace?default('')}/mp/auth/func-datagrid.json?key=${key?default('')}',{'model.id':auth_func_current_model_${action_id}},function(data){
			$('#func_treegrid_${action_id}').treegrid('loadData',data);
		},'JSON');
	}
</script>
<table id="func_treegrid_${action_id}"></table>
<div id="auth_func_datagrid_tb_${action_id}" style="padding:5px;height:auto">
	<div style="margin-bottom:5px">
		<a href="javascript:;;" onclick="auth_func_add_${action_id}();" class="easyui-linkbutton" iconCls="icon-add" plain="true" >${action.getProperty('net.esj.background.message','bg.datagrid.add')}</a>
		<a href="javascript:;;" onclick="$('#func_treegrid_${action_id}').treegrid('expandAll');" class="easyui-linkbutton" iconCls="icon-redo" plain="true" >${action.getText('list.button.expandAll')}</a>
		<a href="javascript:;;" onclick="$('#func_treegrid_${action_id}').treegrid('collapseAll');" class="easyui-linkbutton" iconCls="icon-undo" plain="true" >${action.getText('list.button.collapseAll')}</a>
		<#if key?exists >
		<#else>
		&nbsp;&nbsp;&nbsp;&nbsp;
		${action.getText('func.model.select')}:
		<select class="easyui-combobox" panelHeight="auto" style="width:250px" data-options="
			onChange:function(n,o){
				auth_func_current_model_${action_id} = n;
				auth_func_reload_${action_id}();
			}
		">
			<#list models as model >
				<option value="${model.id}">${model.title}</option>
			</#list>
		</select>
		</#if>
	</div>
</div>
<!--div id="admin_cdgl_menu" class="easyui-menu" style="width:120px;display: none;">
	<div onclick="admin_cdgl_appendFun();" data-options="iconCls:'icon-add'">增加</div>
	<div onclick="admin_cdgl_deleteFun();" data-options="iconCls:'icon-remove'">删除</div>
	<div onclick="admin_cdgl_editFun();" data-options="iconCls:'icon-edit'">编辑</div>
</div-->